package com.play2gether;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.content.Intent;
import android.widget.Toast;

/**
 * Created by Raul on 19/04/14.
 */
public class FragmentMenuPrincipal extends Fragment implements View.OnClickListener {
    public Button btSalir;
    public  Button             btPerfil;
    public  Button             btVincular;
    public  Button             btJugar;
    public  Button             btKamasutra;
    public  Button             btOpciones;
    public  Button             btFormulario;
    public SharedPreferences preferencias;
    public  String             id;
    public int estado;
    public String url;
    private DataBaseManager db;

    public  View vista;

    public static final String TAG = "FragmentMenuPrincipal";

    /*public static FragmentMenuPrincipal newInstance(Bundle arguments){
        FragmentMenuPrincipal f = new FragmentMenuPrincipal(arguments);
        if(arguments != null){
            f.setArguments(arguments);
        }
        return f;
    }*/

    /*public FragmentMenuPrincipal(Bundle arguments){}*/

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_menu_principal, container, false);
        Button boton = (Button) view.findViewById(R.id.btPerfil);
        boton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(),loginActivity.class);
                getActivity().finish();
                startActivity(intent);
            }
        });
        return view;
    //}



    // TODO Auto-generated method stub


        // Comprobamos si se recupera de un estado anterior
        //url = "http://mediadomeprojects.com/arkdyanbyte/play2gether/public/pooling";

        //preferencias = getSharedPreferences("sesion", Context.MODE_PRIVATE);
        //id = preferencias.getString("id", "");
        //String sesionActiva = preferencias.getString("activa","");

        //db = new DataBaseManager(this);
       // vista = getActivity().findViewById(R.id.act);



       // btSalir.setOnClickListener(this);
       // btPerfil.setOnClickListener(this);
       /* btVincular.setOnClickListener(this);
        btJugar.setOnClickListener(this);
        btKamasutra.setOnClickListener(this);
        btOpciones.setOnClickListener(this);
        btFormulario.setOnClickListener(this);*/

       // return inflater.inflate(R.layout.fragment_menu_principal, container, false);
    }
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
    }
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        btPerfil.setOnClickListener(this);
    }

    //El Fragment ha sido creado
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     /*   btSalir     = (Button)       getActivity().findViewById(R.id.btSalir);
        btPerfil    = (Button)       getActivity().findViewById(R.id.btPerfil);
        btVincular  = (Button)       getActivity().findViewById(R.id.btVincular);
        btJugar     = (Button)   getActivity().findViewById(R.id.btJugar);
        btKamasutra = (Button)   getActivity().findViewById(R.id.btKamasutra);
        btOpciones = (Button)   getActivity().findViewById(R.id.btOpciones);
        btFormulario = (Button)   getActivity().findViewById(R.id.btFormulario);*/


    }

    @Override
    public void onClick(View v) {

        Intent intent;
        switch (v.getId()) {
            case R.id.btSalir:  //guardarSesion("0");
                intent = new Intent(this.getActivity(),loginActivity.class);
                this.getActivity().finish();
                startActivity(intent);
                break;
            case R.id.btPerfil:

//pero no se carga en pantalla esta activity estando en otra actividad
                intent = new Intent(getActivity(), PerfilActivity.class);
                getActivity().startService(intent);

                break;
            case R.id.btFormulario:
                intent = new Intent(this.getActivity(),formularioActivity.class);
                startActivity(intent);
                break;
            case R.id.btVincular:
                /*if(verificaConexion(this)){
                    try {
                        new consultarVinculacion().execute();
                    } catch (Exception e) {
                        e.printStackTrace();
                        Log.e("ERROR", e.getMessage());
                    }
                }else {
                    mostrarAlerta("No hay conexión", "Prueba de nuevo cuando estés conectado a la red!!");
                }*/
                break;
            case R.id.btJugar: //Toast.makeText(vista.getApplicationContext(), "btJugar tocado", Toast.LENGTH_SHORT).show();


                break;
            case R.id.btKamasutra: intent = new Intent(this.getActivity(),IndiceKamasutraActivity.class);
                startActivity(intent);
                break;
            case R.id.btOpciones:  Toast.makeText(this.getActivity().getApplicationContext(), "btOpciones tocado", Toast.LENGTH_SHORT).show();
                intent = new Intent(this.getActivity(),contenedorMenuPrincipalActivity.class);
                startActivity(intent);
                break;
        }
    }
}

